<?php

namespace App\Http\Controllers;

use App\Pic;
use Illuminate\Http\Request;
use App\Sqlgoods;
use Illuminate\Support\Facades\Storage;
use App\Goods;
use Maatwebsite\Excel\Facades\Excel;
class HomeController extends Controller
{
    /**php
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('auth');
    }

    /**
     * Show the application dashboard.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        return view('info.mycompany');
    }
    public function mycompany()
    {
        return view('info.mycompany');
    }
    public function log()
    {
        return view('log');
    }
    public function rules()
    {
        return view('user.rules');
    }
    public function url()
    {
        return view('user.url');
    }
    public function user()
    {
        return view('user.home');
    }

    public function order()
    {
        return view('info.order');
    }

    public function goods()
    {
        return view('info.goods');
    }

    public function brand()
    {
        return view('info.brand');
    }
    public function color()
    {
        return view('info.color');
    }
    public function size()
    {
        return view('info.size');
    }
    public function client()
    {
        return view('info.client');
    }
    public function supplier()
    {
        return view('info.supplier');
    }
    public function group()
    {
        return view('info.group');
    }
    public function fund()
    {
        return view('info.fund');
    }
    public function shop()
    {
        return view('shop.shop');
}
    public function imgPost(Request $request)
    {
        if ($request->hasFile('file')) {
            $path = Storage::putFile('', $request->file('file'));
            $newName='alioss'.time().rand(100,999).'.jpg';
            Storage::rename($path,$newName);
            return response()->json($newName);
        } else {
            $file_Name = "storage/uploads/nophoto.jpg";
            return response()->json($file_Name);
        }
    }
    public function postNewOrder(Request $request)
    {
        if ($request->hasFile('file')) {
            $path = Storage::putFile('', $request->file('file'));
            $newName='alioss'.time().rand(100,999).'.jpg';
            Storage::rename($path,$newName);
            return response()->json($newName);
        } else {
            $file_Name = "storage/uploads/nophoto.jpg";
            return response()->json($file_Name);
        }
    }

    public function mssql()
    {
        $sqlGoods=Sqlgoods::all();
        return response()->json($sqlGoods);
    }
    public function door()
    {
        $goods=Pic::all();

       foreach ($goods as $g){
           $g->url=substr($g->url,47);
         $g->save();
       }

    }
    public function excel()
    {

        Excel::load('ex.xls', function($reader) {

            $results = $reader->get();
            $i=0;
            foreach ($results as $rs){
                $i=$i+1;
                $add['company']=6;
                $add['code']='code'.time().$i;
                $add['name']=$rs['title'];
                $add['salePrice']=$rs['price'];
                $add['count']=$rs['num'];
                $add['content']=$rs['description'];
                Goods::create($add);
            }



        });
    }




}
